<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>权限管理 - 帐号管理</title>
    <#include "/pages/include/head.ftl" />
	<style type="text/css">
div{
	border:0;
	text-align:center;
	font-size:12px;
}
#treeLeft{
	width:50%;
	float:left;
}
#treeRight{
	width:50%;
	float:right;
}
</style>
</head>
<body>
<div class="page-top-bar">
<ul class="path">统一帐号管理<span>&gt;</span>系统绑定帐号</ul>
</div>
<div class="function-bar">

<ul class="form-function">
    <li><a id="btn_addSystem"><img src="${contextPath}/images/ico16/group_link.gif" alt="添加绑定" title="添加绑定" /><span>添加绑定</span></a></li>
    <li><a id="btn_deleteSystem"><img src="${contextPath}/images/ico16/link_break.gif" alt="解除绑定" title="解除绑定" /><span>解除绑定</span></a></li>
    <li id="menu1"><a id="btn_changeStatus"><img src="${contextPath}/images/ico16/ico_commission_16.gif" alt="设置用状态" border="0" title="设置状态" /> 设置状态</a></li>
</ul>
</div>
<div class="list-container" >
<div class="list-search">
<form id="search_form" name="search_form">
<ul>
<li>帐户名称：<input name="criteria.username"/></li>
<li>真实姓名：<input name="criteria.realName"/></li>
<li class="search-btn-area">
      <div class="btn-order">
        <ul>
          <li class="left-normal" id="btn1_11"></li>
          <li id="submit" class="middle-normal"><img src="${contextPath}/images/ico16/ico-search.gif" alt="查询" />查 询</li>
          <li class="right-normal" id="btn1_13"></li>
       </ul>
      </div>
	</li>
</ul>
</form>
<script>
<!-- lingen.liu 由于此页面有两个Grid，使用默认的搜索会导致出错，因此重写搜索的方法-->
$(function(){ 
   $('#submit').click(function(){
				var sdata={};
				var params = $('#search_form').serializeArray();
				for(var index in params){
					var name = params[index].name;
					var value = params[index].value;
					if(value!=null && value!="")
					sdata[name] = value;
				}
	    $('#accountGrid').trigger("grid-filter", sdata);
   });
});
</script>
</div>
<div id="treeLeft">

<input type="hidden" name="account_id"/>
<@rw.grid 
    	id="accountGrid" 
    	caption="帐户" 
    	dataType="json" 
    	pager="true" 
    	width="500"
    	gridModel="gridModel"
    	rowList="10,15,20"
    	rowNum="10"
    	rownumbers="true"
    	onSelectRowTopics="rowselect"
    	onGridCompleteTopics="grid-complete">
    	<@sj.gridColumn name="id" index="id"    title="ID" 	sortable="false" hidden="true" />
    	<@sj.gridColumn name="username" 		index="username"		title="帐户名称" />
        <@sj.gridColumn name="realName" 			index="realName"			title="用户真实姓名" 	sortable="false"/>
        <@sj.gridColumn name="email" 			index="email"			title="E-Mail" 	sortable="false"/>   
        <@sj.gridColumn name="locked" 			index="locked"		title="锁定状态" 	sortable="false"/>  
</@rw.grid>
</div>
<div id="treeRight">
<@rw.grid 
	id="systemAccountGrid" 
	caption="系统信息" 
	pager="true"
	gridModel="gridModel"
	rowList="10,15,20"
	rowNum="10"
	rownumbers="true"
	multiselect="true"
	width="400"
	onGridCompleteTopics="grid-complete">
	<@sj.gridColumn name="bizSystem.id" 	hidden="true"	index="bizSystem.id"			title="系统ID" 	sortable="false"/>
	<@sj.gridColumn name="bizSystem.name" 		index="bizSystem.name"			title="系统名称" 	sortable="false"/>
	<@sj.gridColumn name="bizSystem.serialNumber" index="bizSystem.serialNumber"	title="系统注册序列号" />
	<@sj.gridColumn name="status"		index="status"		formatter="icon"	title="状态"  sortable="false"/>
</@rw.grid>

<!-- lingen.liu 状态设置的JDialog -->
<@sj.dialog
        id="resetStatu"  
        buttons="{  
                '确定':function() { resetStatus();$(this).dialog('close'); }, 
                '取消':function() { $(this).dialog('close'); }  
                }"  
        autoOpen="false"
        modal="true"  
        title="状态设置"
    >
    
    <input type="hidden" name="resetStatu_id"/>
    <input type="hidden" name="resetStatu_systemIds"/>
     <table cellpadding="0" cellspacing="0" class="form-2column">
  <tr>
      <th height="50">有效状态：</th>
      <td ><input type="radio" name="radiobutton" value="1">
        启用
        <input type="radio" name="radiobutton" value="0">
        停用</td>
    </tr>
</table>
</@sj.dialog>

<!-- lingen.liu 绑定系统的JDialog -->
<@sj.dialog  
        id="accountBindSystems"  
        buttons="{  
                '确定':function() { addAccountSystemBinding();$(this).dialog('close'); }, 
                '取消':function() { $(this).dialog('close'); }  
                }"  
        autoOpen="false"  
        modal="true"  
        title="添加系统绑定" 
        width="700"
        height="400"
    > 
    
  <input type="hidden" name="accountBindSystems_id"/>
  
<!--列表-->
<div id="grid" class="border-lbr">

    <@rw.grid 
	id="accountSystemBindingGrid" 
	caption="系统信息" 
	pager="true"
	gridModel="gridModel"
	rowList="10,15,20"
	rowNum="10"
	rownumbers="true"
	multiselect="true"
	width="600"
	onGridCompleteTopics="grid-complete">
	<@sj.gridColumn name="id" 		index="id"	 hidden="true"		title="id" 	sortable="false"/>
	<@sj.gridColumn name="name" 		index="name"			title="系统名称" 	sortable="false"/>
	<@sj.gridColumn name="serialNumber" index="serialNumber"	title="系统注册序列号" />
	<@sj.gridColumn name="url" 		index="url"			title="系统名称" 	sortable="false"/>
	<@sj.gridColumn name="status"		index="status"			title="状态"  sortable="false" formatter="icon"/>
</@rw.grid>
</@sj.dialog>

</div>
</div>
</body>
<script type="text/javascript">
  $(function(){
  
   <!-- lingen.liu 点击左边Account的某条记录，右边System查询出相应的记录 -->
   $.subscribe('rowselect', function(event,data) {
      
      var sdata={};
	  sdata["criteria.id"] = event.originalEvent.id;
      $('#systemAccountGrid').trigger("grid-filter", sdata);
      
      $("input[name='account_id']").val(event.originalEvent.id);
    });
    
    <!-- lingen.liu 删除一个帐号同一些系统绑定的方法  -->
    $('#btn_deleteSystem').click(function(){
        var accountselectedIds = $("input[name='account_id']").val();
        if(accountselectedIds==""){
           alert("未选中帐号");
           return;
        }
        var systemselectIds = $("#systemAccountGrid").jqGrid('getGridParam','selarrrow');
        
        if(systemselectIds == ""){
          alert("未选中任何系统");
          return;
        }
        
        var systemIds = new Array();
        for(var i=0;i<systemselectIds.length;i++){
           var colId = systemselectIds[i];
           systemIds[i] = $("#systemAccountGrid").jqGrid('getCell',colId,'bizSystem.id');
        }
        
        var yes = confirm("确认解除绑定?");
        if(yes){
        var reqParams = {id:accountselectedIds,systemIds:systemIds};
         $.ajax({                                                
          type: "POST",                                     
          url: "paramAccount-accounUnBindSystems.action",                                   
          data: reqParams,   
          success: function(msg){
             alert("ok,成功解除绑定");
             $('#systemAccountGrid').trigger("reloadGrid");
          } 
        });
        }
    });
    
    <!-- lingen.liu 添加绑定功能打开绑定窗口的方法 -->
    $('#btn_addSystem').click(function(){
        
        var selectedIds = $("input[name='account_id']").val();
        if(selectedIds==""){
           alert("未选中帐号");
           return;
        }
        
       $("input[name='accountBindSystems_id']").val(selectedIds);
      var sdata={};
	  sdata["criteria.id"] = selectedIds;
      $('#accountSystemBindingGrid').trigger("grid-filter", sdata);
        $('#accountBindSystems').dialog('open');
    });

  
  
  
  <!-- lingen.liu 点击设置状态，进行必要的检验及弹出设置状态界面 -->
  $('#btn_changeStatus').click(function(){
 
      var systemselectIds = $("#systemAccountGrid").jqGrid('getGridParam','selarrrow');
      
      
      var accountselectedIds = $("input[name='account_id']").val();
      
        if(accountselectedIds==""){
           alert("未选中帐号");
           return;
        }
        
        if(systemselectIds==""){
           alert("未选中系统");
           return;
        }
        
        var systemIds = new Array();
        for(var i=0;i<systemselectIds.length;i++){
           var colId = systemselectIds[i];
           systemIds[i] = $("#systemAccountGrid").jqGrid('getCell',colId,'bizSystem.id');
        }
        
       $("input[name='resetStatu_id']").val(accountselectedIds);
       $("input[name='resetStatu_systemIds']").val(systemIds);
       $('#resetStatu').dialog('open');
  });
  
  });
  
  <!-- lingen.liu 修改一个帐号的绑定的某个系统设置为可用或不可用 -->
  function resetStatus(){
    var id = $("input[name='resetStatu_id']").val();
    var systemIds = $("input[name='resetStatu_systemIds']").val();
    var statu = $("input[name='radiobutton']:checked").val();
    var reqParams = {id:id,systemIds:systemIds,status:statu};
    
     $.ajax({                                                
          type: "POST",                                     
          url: "paramAccount-resetLock.action",                      
          data: reqParams, 
          success: function(msg){
             alert("状态修改成功");
             $("#systemAccountGrid").trigger("reloadGrid");
          } 
        });
  }
  
  <!-- lingen.liu 为一个帐号添加系统绑定-->
  function addAccountSystemBinding(){

      var id = $("input[name='accountBindSystems_id']").val();
      var selectedIds = $("#accountSystemBindingGrid").jqGrid('getGridParam','selarrrow');
          if(selectedIds==""){
            alert("未选中任何系统");
            return;
          }else{
            var yes = confirm("确认添加这些绑定？");
            if(yes){
        var reqParams = {id:id,systemIds:selectedIds};
     $.ajax({                                                
          type: "POST",                                     
          url: "paramAccount-accountBindSystems.action",                                   
          data: reqParams,   
          success: function(msg){
             alert("OK，绑定成功");
             $("#systemAccountGrid").trigger("reloadGrid");
          }
        });
      }}
  }
</script>
</html>